package com.tgy.JUC.Help;

import java.util.concurrent.CountDownLatch;

/***
 * @ClassName: CountDownLatchTest
 * @Description: 测试 CountDownLatch
 * @Auther: 送你一块二向箔
 * @Date: 15:34 2022/3/11
 * @version : V1.0
 */
public class CountDownLatchTest {
    public static void main(String[] args) {
        run();
    }

    public static void run() {
        // 总数是6，必须要是执行任务的时候使用
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "=>Go Out");
                countDownLatch.countDown();// 数量-1
            }).start();
        }
        try {
            countDownLatch.await();// 等待计数器归零，然后再往下执行
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("关门");
    }
}
